package com.dragon.common.modules.uaa.web.models.params;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author Chris Chan
 * Create On 2025/8/8 下午12:29
 * Use for:
 * Explain:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "邮箱验证码修改密码参数")
public class UpdatePasswordByEmailVerifyCodeParam implements Serializable {
    private static final long serialVersionUID = 1L;

    @NotBlank(message = "邮箱不能为空")
    @Email(message = "邮箱格式错误")
    @Schema(description = "邮箱")
    private String email;

    @NotBlank(message = "验证码不能为空")
    @Schema(description = "验证码")
    private String verifyCode;

    @NotBlank(message = "新密码不能为空")
    @Size(min = 6, max = 20, message = "新密码长度必须在6-20之间")
    @Schema(description = "新密码")
    private String newPassword;

    @NotBlank(message = "确认密码不能为空")
    @Size(min = 6, max = 20, message = "确认密码长度必须在6-20之间")
    @Schema(description = "确认密码")
    private String confirmPassword;

    public static UpdatePasswordByEmailVerifyCodeParam create(String email, String verifyCode, String newPassword, String confirmPassword) {
        return new UpdatePasswordByEmailVerifyCodeParam(email, verifyCode, newPassword, confirmPassword);
    }

    public static UpdatePasswordByEmailVerifyCodeParam of(String email, String verifyCode, String newPassword, String confirmPassword) {
        return new UpdatePasswordByEmailVerifyCodeParam(email, verifyCode, newPassword, confirmPassword);
    }

    @AssertTrue(message = "两次输入的密码不一致")
    public boolean isPasswordMatch() {
        return newPassword.equals(confirmPassword);
    }
}
